<!DOCTYPE html>
<html>
<head>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes" />
	<meta name="apple-mobile-web-app-capable" content=true />
	<link rel="stylesheet" href="__PUBLIC__/com/jquery/jquery.mobile.min.css"/>
	<script src="__PUBLIC__/com/jquery/jquery.min.js"></script>
	<script src="__PUBLIC__/com/jquery/jquery.mobile.min.js"></script>
	<script src="__PUBLIC__/com/vue/vue.js"></script>
	<script src="__PUBLIC__/com/clipboard/clipboard.min.js"></script>
	<script src="__PUBLIC__/com/jsUtill/alert.js"></script>
	<script src="__PUBLIC__/com/jsUtill/dataFunc.js"></script>

	<meta charset="utf-8">
	<title>App</title>
</head>
<body>

	<div data-role="page" id="pageSet">
		<div data-role="header">
			<h1>App</h1>
			<a href="./publish.html">发布</a>
			<button onclick="togEdit()" data-inline="true"  style="padding: 0  5pt 0 5pt;position: absolute;top: -2px;right: 10pt;height: 30pt;font-size: 9pt;" >编辑</button>
		</div>
		<div data-role="content" class="app" id="app">

			<div class="cntapp">
				<div class="card" v-for="(item, key) in apps">
					
				<!--<button class="fname" onclick="toggle(this)" :data-id="key" id="btnToggle" flag='0'>{{ key }} </button>
				 <button onclick="toggle(this)" :data-id="key" id="btnToggle" flag='0'>展开</button> 
				
				 <pre @id="{{ key }}" hidden="true"><button class="copy" onclick="copyCode(this)" :data-id="key" flag='0'>复制</button><xmp> {{item}} </xmp></pre>-->

				 <div v-if="item.type == 'iOS'">
				 	<img src="__IMAGE__/app/ios.png">
				 	<a :href="'itms-services:///?action=download-manifest&amp;url='+item.plist">{{ item.appname }} {{ item.version }} </a>
				 </div>
				 <div v-else>
				 	<a :href="item.appurl" target=""><img src="__IMAGE__/app/android.png">
				 	{{ item.appname }} {{ item.version }}</a>
				 </div>
				 <p>发布时间：{{ item.savetime }}</p>
				 <p>版本信息:{{ item.description }}</p>
				 <div class="menu">
				 	
				 	<button @click="deleteData(item.id)" hidden="true" data-inline="true" class="btn_delete">删除</button>
				 	<!-- <button @click="editData(this,item.id)" hidden="true" data-inline="true" class="btn_Edit">编辑</button> -->
				 </div>
				</div>

			</div>

			<pre id="obj"></pre>
		</div>
		<div data-role="footer" style="display: none;">
			<h1>e6jpfei</h1>
		</div>
	</body>
	<script type="text/javascript">
		

		var url = window.location.href;
		var type = getArgsFromHref(url,'type');
		if (type == "") {
			type = "flutter";
		}

		function togEdit(){
			$(".btn_delete").toggle();
			$(".btn_Edit").toggle();
		}

		function deleteData(id){
			$.ajax({
				type:"post",
				url:"./delete",
				data:{id:id},
				success:function(res){
					if (typeof res === "string") {
					//showData(JSON.parse(res));
					alert("删除成功");
					queryCode();
				}else{
					//showData(res);
				}
			},
			error: function(e) { 
			// alert(e.message); 
		} 
	});
		}

		function queryCode()
		{
			$.ajax({
				type:"post",
				url:"./app",
			//data:{fileName:fileName,type:type},
			success:function(res){
				if (typeof res === "string") {
					showData(JSON.parse(res));
				}else{
					showData(res);
				}
			},
			error: function(e) { 
			// alert(e.message); 
		} 
	});
		}

		function download(){

		}

		function showData(obj){
			var dic = obj["data"];
			vm.$data.apps = dic;
			dicCode = dic;
		}

		var vm = new Vue({
			el: "#app",
			data: {
				apps: []
			}
		})

		function toggle(v){
			var cnt = $(v).parent();
			var pre = cnt.children("pre");
			var btn = cnt.children("button#btnToggle");
			if (btn.attr("flag")=="0") {
				pre.show();
				btn.attr("flag","1");
				btn.css("color","#09f");
			}else{
				pre.hide();
				btn.attr("flag","0");
				btn.css("color","#666");
			}
		}

		function copyCode(v)
		{
			var bomID = $(v).data("id");

			var clipboard = new ClipboardJS("#cntCode", {
				text: function() {
					return dicCode[bomID];
				}
			});

			clipboard.on('success', function(e) {
        //console.log(e);
        Toast('复制成功',2000)
    });

			clipboard.on('error', function(e) {
				console.log(e);
				Toast('复制失败',2000)
			});
		}

		queryCode();


	</script>
	<style type="text/css">
	.cntCode{
		padding: 10px;
	}

	.menu{
		position: absolute;
		padding: 10pt 0 0 0;
		top: 0;
		right: 0;
		bottom: 0;
		width: 60pt;
	}
	.menu button{
		width: 55pt;
	}

	img{
		width: 30pt;
		height: 30pt;
	}

	.cntapp{
		background-color: #f2f3f4;
		padding: 0px 0px 5px 0px;
	}

	.card{
		background-color: #fff;
		margin: 0px 0px 5px 0px;
		padding: 5pt;
		position: relative;
	} 

	.title{
		background-color: #ddd;
		font-size: 32px; 
		font-weight: bold; 
		border-bottom-width: 2px;
		border-bottom-style: solid; 
		border-bottom-color: rgb(204, 204, 204); 
		padding: 0px 4px 0px 0px; 
		text-align: left; 
		margin: 0px 0px 10px;
	}
	a{
		font-size: 12pt;
	}

	.copy{
		border: none;
		background-color: #f1f2f3;
		color: #4c90bc;
	}
</style>
</html>